Passed
Push — master ( aea7d3...cd8e9c )
by Seonkuk
06:06 queued 03:59
created

Loading.render   A

Complexity

Conditions 2

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
import React from 'react';
2
import PropTypes from 'prop-types';
3
4
export default class Loading extends React.Component {
5
  constructor(props) {
6
    super(props);
7
    this.state = {
8
      style: { display: 'none' },
9
    };
10
  }
11
12
  componentWillReceiveProps(newProps) {
13
    if (newProps.show) {
14
      this.setState({ style: {} });
15
    } else if (this.props.show && !newProps.show) { // true => false
16
      // set display to 'none' after 1 sec (for fade-out animation)
17
      setTimeout(() => this.setState({ style: { display: 'none' } }), 1000);
18
    }
19
  }
20
21
  render() {
22
    return <div className={`loading-backdrop fade ${this.props.show ? 'in' : ''}`} style={this.state.style}><div className="loading" /></div>;
23
  }
24
}
25
26
Loading.defaultProps = {
27
  show: false,
28
};
29
30
Loading.propTypes = {
31
  show: PropTypes.bool,
32
};
33